﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace CorreoSocialWeb.Views
{
    public class IntValidator
    {
        public int? Min {get; protected set;}
        public int? Max {get; protected set;}

        public IntValidator(int? min, int? max)
        {
            this.Min = min;
            this.Max = max;
        }

        public int? Get(string text)
        {
            int? v = null;

            Validate(text, out v);

            return v;
        }

        public bool Validate(string text)
        {
            int? dummy;

            return Validate(text, out dummy);
        }

        public bool Validate(string text, out int? value)
        { 
            value = null;

            int i;

            if (!int.TryParse(text, out i))
                return false;

            if (Min.HasValue && i < Min.Value)
                return false;

            if (Max.HasValue && i > Max.Value)
                return false;

            value = i;

            return true;
        }
    }

    public class HoraValidator : IntValidator
    {
        public HoraValidator()
            : base(0, 23)
        { }
    }

    public class MinutoValidator : IntValidator
    {
        public MinutoValidator()
            : base(0, 59)
        { }
    }
}